<%--
  Created by IntelliJ IDEA.
  User: YYY-Work
  Date: 2017/7/31
  Time: 15:43
  To change this template use File | Settings | File Templates.
--%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<%@ taglib prefix="s" uri="/struts-tags" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://"
            + request.getServerName() + ":" + request.getServerPort()
            + path;
%>
<!DOCTYPE>
<html>
<head>
    <title>上传健康档案</title>
    <meta charset="UTF-8">
    <meta content='width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no' name='viewport'>

    <script type="text/javascript" src="<%=basePath%>/js/jquery-2.1.1.min.js"></script>

    <style type="text/css">
        .table th, .table td {
            text-align: center;
            vertical-align: middle !important;
        }
    </style>
</head>
<body class="skin-blue">
<s:action name="getHeader" namespace="/privilege" executeResult="true"/>
<div class="wrapper row-offcanvas row-offcanvas-left">

    <!-- Left side column. contains the logo and sidebar -->

    <!-- getMenus -->
    <s:action name="getMenus" namespace="/privilege" executeResult="true"/>

    <!-- Right side column. Contains the navbar and content of the page -->
    <aside class="right-side">

        <!-- Content Header (Page header) -->
        <section class="content-header">
            <h1>
                <small>上传健康档案</small>
            </h1>
        </section>

        <!-- Main content -->
        <section class="content">
            <div class="row">
                <div class="col-xs-12">
                    <div class="box">

                        <div class="box box-danger">

                            <div class="box-body">

                                <form action="javascript:searchGoodsDataUser();" class="form-horizontal"
                                      name="searchForm">

                                    <div class="form-group">
                                        <lable style="float: left;margin-left: 30px">用户ID</lable>
                                        <input type="text" id="ownerId" class="col-sm-2"
                                               style="float: left;margin-left: 30px">
                                        <lable style="float: left;margin-left: 30px">用户姓名</lable>
                                        <input type="text" id="ownerName" class="input-small col-sm-2"
                                               style="float: left;margin-left: 30px">

                                        <button type="submit" class="btn btn-primary" style="margin-left: 15px">查询
                                        </button>
                                    </div>
                                </form>
                            </div><!-- /.box-body -->
                        </div><!-- /.box -->
                        <!-- 文章列表 -->
                        <form method="post" target="_self" action="" name="listForm">
                            <div class="box-body table-responsive" id="listDiv">

                                <s:property value="res" escape="false"/>
                            </div><!-- /.box-body -->
                        </form>

                    </div><!-- /.box -->


                </div>
            </div>

        </section><!-- /.content -->

    </aside>
</div>
</body>

<script type="text/javascript" src="<%=basePath%>/js/admin/utils.js"></script>
<script type="text/javascript" src="<%=basePath%>/js/base/listtable.js"></script>
<link href="<%=basePath%>/css/fileinput.css" media="all" rel="stylesheet" type="text/css"/>
<link href="<%=basePath%>/themes/explorer/theme.css" media="all" rel="stylesheet" type="text/css"/>
<script src="<%=basePath%>/js/sortable.js" type="text/javascript"></script>
<script src="<%=basePath%>/js/fileinput.js" type="text/javascript"></script>
<script src="<%=basePath%>/js/locales/zh.js" type="text/javascript"></script>
<script src="<%=basePath%>/themes/explorer/theme.js" type="text/javascript"></script>

<div class="modal fade" id="UploadModal" tabindex="-2" role="dialog" aria-labelledby="messageModalLabel"
     aria-hidden="true">

    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <h4 class="modal-title">
                    上传健康档案
                </h4>
            </div>
            <div class="modal-body" id="modal-body">

                <form id="uploadHealthFileForm" enctype="multipart/form-data">
                    <input name="recid" style="display: none" id="recid"/>
                    <input name="ownerId" style="display: none" id="ownerId1"/>

                    <div class="form-group">
                        <lable >选择就诊人</lable>
                        <div >

                            <div id="patient_name">
                            </div>

                            <input id="patient_id" name="patientId" style="display: none" />

                            <div>
                                <button class="btn btn-success btn-xs" onclick="selectPatient()" type="button">
                                    选择
                                </button>
                                <button class="btn btn-danger btn-xs" onclick="removeSelectPatient()" type="button">
                                    移除
                                </button>
                            </div>


                        </div>

                    </div>
                    <div id="add_detail">

                    </div>
                </form>

            </div>
            <div class="modal-footer">
                <button type="btm" class="btn btn-primary" onclick="uploadHealthFile()">上传</button>
                <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
            </div>
        </div><!-- /.modal-content -->
    </div><!-- /.modal -->
</div>

<div class="modal fade" id="SelectPatientModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <h4 class="modal-title" id="myModalLabel">选择就诊人</h4>
                <div style="margin-top: 15px;vertical-align: middle;">
                    <form id="search-patient-form">

                        <input type="text" name="isUsedFlag" style="display: none" value="1">
                        <input type="text" id="UserId" name="userid" style="display: none">
                        <input type="text" id="stuff_search_name" name="patientName" class="col-sm-3" style="padding-top: 3px;padding-bottom: 3px" placeholder="请输入就诊人姓名">
                        <input name="currentPage" type="text" value="1" style="display: none">
                        <input name="pageSize" type="text" value="100" style="display: none">
                    </form>
                    <button type="button" class="btn btn-primary btn-sm" style="margin-left: 15px" onclick="searchPatient()">查询</button>
                </div>
            </div>
            <div class="modal-body" id="patient-list" style="height: 400px;max-height:400px;overflow-y:scroll">

            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
            </div>
        </div><!-- /.modal-content -->
    </div><!-- /.modal -->
</div>

<script type="text/javascript">

    function searchGoodsDataUser() {

        var ownerId = Utils.trim($("#ownerId").val());
        var ownerName = Utils.trim($("#ownerName").val());

        listTable.filter['ownerId'] = ownerId;
        listTable.filter['ownerName'] = ownerName;
        listTable.filter['operFlag'] = 0;
        listTable.filter['currentPage'] = 1;
        listTable.action = "<%=basePath%>/healthrecord/ajaxQueryHealthRecordsForUpload.action";

        listTable.loadList();
    }

    function selectPatient() {
        $("#UserId").val($("#ownerId1").val());
        $("#SelectPatientModal").modal('show')
        searchPatient();
    }

    function removeSelectPatient() {
        $("#patient_name").empty();
        $("#patient_name").append("<label>"+patientName+"</label>");
        $("#patient_id").val(patientid);
    }

    function searchPatient() {
        var formData =new FormData($('#search-patient-form')[0]);//
        $.ajax({
            type:"POST",
            url:"<%=basePath%>/patient/ajaxQueryPatientForSelect.action",
            data:formData,
            async: false,
            contentType: false,
            processData: false,
            error: function(request) {
                alert("网络异常");
            },
            success: function(data) {
                data=JSON.parse(data);
                if(!Utils.isEmpty(data.content))
                {
                    $("#patient-list").empty();
                    $("#patient-list").append(data.content);
                }
            }
        });
    }

    function onPatientSelect(patientid,patientName) {

        $("#patient_name").empty();
        $("#patient_name").append("<label>"+patientName+"</label>");
        $("#patient_id").val(patientid);
        $("#SelectPatientModal").modal('hide')
    }

    function showUploadModal(recid,ownerId) {

        $("#recid").val(recid);
        $("#ownerId1").val(ownerId);
        $("#patient_name").empty();
        $("#patient_id").val("");

        var aa='<div class="form-group">\n' +
               '<label>健康档案文件</label>\n' +
               '<input type="file" class="form-control" name="excel" id="excel">\n' +
               '</div>';

        $("#add_detail").empty();
        $("#add_detail").append(aa);

        $("#excel").fileinput({
            language: 'zh', //设置语言 
            showUpload: false, //是否显示上传按钮  
            showCaption: true,//是否显示标题
            allowedFileExtensions: ['xls', 'xlsx'],
            maxFileCount: 1,//最大上传文件数限制
            previewFileIcon: '<i class="glyphicon glyphicon-file"></i>',
            allowedPreviewTypes: null,
            previewFileIconSettings: {
                'docx': '<i class="glyphicon glyphicon-file"></i>',
                'xlsx': '<i class="glyphicon glyphicon-file"></i>',
                'pptx': '<i class="glyphicon glyphicon-file"></i>',
                'jpg': '<i class="glyphicon glyphicon-picture"></i>',
                'pdf': '<i class="glyphicon glyphicon-file"></i>',
                'zip': '<i class="glyphicon glyphicon-file"></i>',
            },
        });

        $('#UploadModal').modal('show');
    }
    
    function uploadHealthFile() {

        var excelFile=$("#excel").val();
        var patientId=$("#patient_id").val();
        if (!Utils.isEmpty(excelFile))
        {
            if (!Utils.isEmpty(patientId))
            {
                var formData = new FormData($('#uploadHealthFileForm')[0]);//
                $('#UploadModal').modal('hide');
                $.ajax({
                    type: "POST",
                    url: "<%=basePath%>/healthrecord/ajaxUploadHealthExcelFile.action",
                    data: formData,
                    async: true,
                    contentType: false,
                    processData: false,
                    error: function (request) {
                        alert("网络异常");
                    },
                    success: function (data) {
                        data = JSON.parse(data);
                        if (data.errorCode >= 0) {
                            listTable.loadList();
                            alert("上传健康档案成功");
                        } else {
                            alert(data.errorMsg);
                        }
                    }
                });
            }else
            {
                alert("就诊人不能为空");
            }

        }else
        {
            alert("健康档案不能为空");
        }
    }

    $(document).ready(new function () {
       searchGoodsDataUser();
    });

</script>
</html>
